<?php
	include_once('dbcon.php');
	include_once('constants.php');
	include_once('update_user_points_db.php');

	$contents_query = $mysqli->query("SELECT content_id, likes, dislikes FROM contents ");
    	
    $mysqli->autocommit(false);

    while ($row = $contents_query->fetch_assoc()) {
		$mysqli->query("UPDATE contents SET points='".getContentPoints($row['likes'], $row['dislikes'])."' WHERE content_id='".$row['content_id']."'");
		echo $mysqli->error."</br>";
    }

	$mysqli->commit();
    $mysqli->autocommit(true);

    $users_query = $mysqli->query("SELECT * FROM contents ");

	while ($row = $users_query->fetch_assoc()) {
		updateUserPoints($row['user_id']);
    }
?>